package com.feisuanyz.service.validation.impl;

import com.feisuanyz.dto.LogoValidationQuery;
import com.feisuanyz.dto.RestResult;
import com.feisuanyz.entity.EventManagement;
import com.feisuanyz.entity.LogoManagement;
import com.feisuanyz.repository.EventManagementRepository;
import com.feisuanyz.repository.LogoManagementRepository;
import com.feisuanyz.service.validation.LogoValidationService;
import java.net.URL;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 标志图片验证服务实现类
 */
@Service
@Slf4j
public class LogoValidationServiceImpl implements LogoValidationService {

    @Autowired
    private LogoManagementRepository logoManagementRepository;

    @Autowired
    private EventManagementRepository eventManagementRepository;

    @Override
    public RestResult validateLogo(LogoValidationQuery query, String operation) {
        if ("edit".equalsIgnoreCase(operation) || "delete".equalsIgnoreCase(operation)) {
            if (query.getLogoId() == null) {
                return new RestResult("000001", "标志图片ID不能为空", null);
            }
            LogoManagement logo = logoManagementRepository.findById(query.getLogoId()).orElse(null);
            if (logo == null) {
                return new RestResult("000001", "标志图片ID不存在", null);
            }
        }

        EventManagement event = eventManagementRepository.findById(query.getEventId()).orElse(null);
        if (event == null) {
            return new RestResult("000001", "关联的事件ID不存在", null);
        }

        if (query.getLogoUrl().length() > 255) {
            return new RestResult("000001", "标志图片URL不能超过255个字符", null);
        }

        return new RestResult("000000", "调用成功", null);
    }
}